import java.io.*;
import java.util.*;

/**
 * Encapsulates reading the configuration file and exposing individual
 * values are strongly-typed objects. This class is immutable.
 */
public class EstimatedCosts
{
    /**
     * Initializes a new instance of the EstimatedCosts class.
     */
    public EstimatedCosts(String path) {
        loadFromConfigFile(path);
    }

    /**
     * Returns the cost of accessing an array element.
     */
    public int getCostOfArrayAccess() {
        return this.r;
    }
	
    /**
     * Returns the cost of performing an if test.
     */
    public int getCostOfIfTest() {
        return this.t;
    }
	
    /**
     * Returns the cost of performing a logical "and" (&).
     */
    public int getCostOfLogicalAnd() {
        return this.l;
    }
	
    /**
     * Returns the cost of a branch
     */
    public int getCostOfBranchMisprediction() {
        return this.m;
    }
	
    /**
     * Returns the cost of writing an answer to the answer array and
     * incrementing the answer array counter.
     */
    public int getCostOfAnswerArray() {
        return this.a;
    }
	
    /**
     * Returns the cost of applying function f to its arguments.
     */
    public int getCostOfApplyingFunction() {
        return this.f;
    }
	
    /**
     * Loads the configuration values from the specified file.
     */
    private void loadFromConfigFile(String path) {
        try {
            FileInputStream stream = new FileInputStream(path);
			
            Properties props = new Properties();
            props.load(stream);
			
            // Read each value and set the field accordingly.
            this.r = readInteger(props, "r");
            this.t = readInteger(props, "t");
            this.l = readInteger(props, "l");
            this.m = readInteger(props, "m");
            this.a = readInteger(props, "a");
            this.f = readInteger(props, "f");

            stream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
	
    /**
     * Reads an individual value from the properties file and converts
     * it into an integer.
     */
    private int readInteger(Properties props, String name) {
        String value = props.getProperty(name).trim();
        return Integer.parseInt(value);
    }
	
    private int r;
    private int t;
    private int l; 
    private int m; 
    private int a;
    private int f;
}